<?php

namespace App\Observers\Train;

use App\Models\Train\TrainPoints\TrainPoint;
use Illuminate\Support\Facades\Cache;

class TrainPointObserver
{
    public function creating(TrainPoint $point)
    {

    }


    public function updating(TrainPoint $point)
    {

    }

    public function saving(TrainPoint $point)
    {
    }

    /**
     * Handle the User "created" event.
     *
     * @param TrainPoint $point
     *
     * @return void
     */
    public function created(TrainPoint $point)
    {
        $cache_key = "Train:point:{$point->train_code}:{$point->station_code}";
        Cache::put($cache_key, $point, 10 * config('trip.ttl.day'));
    }

    /**
     * Handle the User "updated" event.
     *
     * @param TrainPoint $point
     *
     * @return void
     */
    public function updated(TrainPoint $point)
    {
        $cache_key = "Train:point:{$point->train_code}:{$point->station_code}";
        Cache::put($cache_key, $point, 10 * config('trip.ttl.day'));
    }

    public function saved(TrainPoint $point)
    {
        $cache_key = "Train:point:{$point->train_code}:{$point->station_code}";
        Cache::put($cache_key, $point, 10 * config('trip.ttl.day'));
    }
}
